home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8094 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: Starbase.NeoSoft.COM!not-for-mail
  2. From: timd@Starbase.NeoSoft.COM (TimD)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: templates & declaration of instances...
  5. Date: 14 Feb 1996 09:47:13 -0600
  6. Organization: NeoSoft, Inc. +1 713 968 5800
  7. Message-ID: <4ft061$631@Starbase.NeoSoft.COM>
  8. References: <4fqf2t$lg0@Starbase.NeoSoft.COM>
  9. NNTP-Posting-Host: starbase.neosoft.com
  10.  
  11. In article <4fqf2t$lg0@Starbase.NeoSoft.COM>,
  12. TimD <timd@Starbase.NeoSoft.COM> wrote:
  13. >I recently ran into a problem with forward definitions of
  14. >template instances.  [...]
  15. >
  16. >   // other.h
  17. >   class some_class;
  18. >   class some_other_class
  19. >   {
  20. >      ...
  21. >      void some_func(some_class *ptr);
  22. >      ...
  23. >   };
  24. >
  25. >and in the body, I can include the definition of
  26. >some_class.  But, if some class is an instance of
  27. >a template, how do I do it?
  28. >
  29. >I tried the following, and, not surprisingly, it didn't work:
  30. >
  31. >   // other.cc
  32. >
  33. >   #include "parameter_class.h"
  34. >   #include "template_class.h"
  35. >
  36. >   typedef some_template_class<some_parameter_class> some_class;
  37. >
  38. >    ...
  39. >     void some_other_class::some_func(some_class *ptr)
  40. >     {
  41. >       ...
  42. >     }
  43. >    ...
  44.  
  45. Okay...someone suggested
  46.  
  47.    class some_class : public some_template_class<some_parameter_class>
  48.  
  49. which would have worked in some classes, but not this one.  This is
  50. because the template class has calls that return ptrs to other
  51. instances of the same class:
  52.  
  53.    template <class C> class some_template_class
  54.    {
  55.       ...
  56.       some_template_class<C> *return_ptr_to_class();
  57.       ...
  58.    }
  59.  
  60. So, now, the following code does not work:
  61.  
  62.    some_class a;
  63.    some_class *b;
  64.  
  65.    b = a.return_ptr_to_class();
  66.  
  67. That's something I wish were differeent about c++...it should be
  68. required to define an explicit class or function that is an 
  69. instance of a template...like Ada's Generics:
  70.  
  71.    class some_class = some_template_class<some_parameter_class>;
  72.  
  73. Why, oh, why did they make it so complicated?  :)
  74.  
  75. -t
  76.